﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace SuperMarketSystem
{
    public partial class ManagerControl : UserControl
    {
        event GetInventoryEventHandler getEvent;
        event FinishedEventHandler finishEvent;
        SelfCheckStation parent;

        public ManagerControl(SelfCheckStation p)
        {
            parent = p;
            InitializeComponent();
            getEvent += parent.geteventhandler;
            finishEvent += parent.finishhandler;

            if (getEvent != null)
                getEvent(this);
            Item i1 = new Item();
            i1.description = "Stuff For You";
            i1.discount = 10;
            i1.name = "yourmom";
            i1.price = 2.45M;
            i1.upcnum = 1928374;
            Item i2 = new Item();
            i2.description = "Stuff For Me";
            i2.discount = 5;
            i2.name = "yourdad";
            i2.price = 3.91M;
            i2.upcnum = 18768702;
            add(i1);
            add(i2);
        }

        public void add(Item i)
        {
            listBox1.Items.Add(i);
        }
        private void button1_Click(object sender, EventArgs e)
        {
            if (finishEvent != null)
                finishEvent(this);
        }

        private void listBox1_ItemSelected(object sender, EventArgs e)
        {
            ItemForm form = new ItemForm(parent, (Item)listBox1.SelectedItem);
            form.ShowDialog();
        }

        private void listbox1_EnterPressed(object sender, KeyPressEventArgs e)
        {
            if (System.Char.IsControl(e.KeyChar))
            {
                ItemForm form = new ItemForm(parent, (Item)listBox1.SelectedItem);
                form.ShowDialog();
            }
        }
    }
}
